# 初始化
CREATE TABLE test04 (
                        id INT PRIMARY KEY AUTO_INCREMENT,
                        b  INT,
                        KEY b(b)
) ENGINE = InnoDB DEFAULT CHARSET = utf8;

INSERT INTO test04
(id, b)
VALUES
(1, 2),
(3, 4),
(5, 6),
(7, 8),
(9, 10);
# 第一个终端sql
BEGIN;
SELECT * FROM test04 WHERE b = 6 FOR UPDATE;
# 第二个终端sql
INSERT INTO test04 VALUES (2, 4);/*success*/
INSERT INTO test04 VALUES (2, 8);/*blocked*/
INSERT INTO test04 VALUES (4, 4);/*blocked*/
INSERT INTO test04 VALUES (4, 8);/*blocked*/
INSERT INTO test04 VALUES (8, 4);/*blocked*/
INSERT INTO test04 VALUES (8, 8);/*success*/
INSERT INTO test04 VALUES (0, 4);/*blocked*/
INSERT INTO test04 VALUES (-1, 4);/*success*/
